package br.com.spring.mvc.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import br.com.spring.mvc.entity.Simple;

@Repository("simpleDAO")
public class SimpleDAO {

	private HibernateTemplate hibernateTemplate;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	
	public int save(Simple entity) {
		return (Integer) hibernateTemplate.save(entity);
	}
	public void update(Simple entity) {
		hibernateTemplate.update(entity);
	}
	public void delete(int id) {
		hibernateTemplate.delete(new Simple(id));
	}
	public List<Simple> loadAll() {
		return hibernateTemplate.loadAll(Simple.class);
	}
	public Simple get(int id) {
		return hibernateTemplate.get(Simple.class, id);
	}
//	public SimpleEntity findByentityCode(Integer id) {
//		List entitys = hibernateTemplate.find(
//				"from SimpleEntity where id = ?", id);
//		return (SimpleEntity) entitys.get(0);
//	}
	
}
